package cn.itsource.controller;

import cn.itsource.domain.Account;
import cn.itsource.service.IAccountService;
import cn.itsource.utils.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class AccountController {
    @Autowired
    private IAccountService accountService;

    @PostMapping("/accountLogin")
    public JSONResult login(@RequestBody Account account) {
        try{
            String token = accountService.getAccount(account.getUserName(),account.getPassword());
            return JSONResult.ok("登陆成功",token);
        } catch (RuntimeException e) {
            e.printStackTrace();
            return JSONResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.fail("系统繁忙中，请重新试试");
        }
    }

}
